/**
 * 路由模块
 */
define(['require', 'jquery', 'LangCtrl', 'loading', 'widget.base', 'CssLoader', 'cookieLib'],
    function () {
        //默认路径
        var defaultUrl = null;
        //上一次路径
        var lastRouteUrl = null
        //当前路径
        var routeUrl = null;

        var routeUrlChangedEvent = WidgetBase.CreateEvent("routeUrlChangedEvent");

        //AP模块列表
        var appModuleList = {
            "main": {
                url: "view/main.html",
                apModule: "app/main",
                subContainer: "#Content"
            },
            "login": {
                url: "view/login.html",
                apModule: "app/login"
            },
            // 一级模块
            "live": {
                url: "view/Live/live.html",
                apModule: "app/Live/live"
            },
            "rec": {
                url: "view/Rec/rec.html",
                apModule: "app/Rec/rec"
            },
            "recBackUp": {
                url: "view/Rec/recBackUp.html",
                apModule: "app/Rec/recBackUp"
            },
            "localConfig": {
                url: "view/localConfig.html",
                apModule: "app/localConfig"
            },
            "configFrame": {
                subContainer: "#configRightFrame",
                apModule: "app/configFrame"
            },
            "cfgHome": {
                url: "view/cfgHome.html",
                apModule: "app/cfgHome"
            },
            "chlCfgFrame": {
                subContainer: "#configRightFrame",
                url: "view/ChlCfg/chlCfgFrame.html",
                apModule: "app/ChlCfg/chlCfgFrame"
            },
            "recCfgFrame": {
                subContainer: "#configRightFrame",
                url: "view/RecCfg/recCfgFrame.html",
                apModule: "app/RecCfg/recCfgFrame"
            },
            "alarmCfgFrame": {
                subContainer: "#configRightFrame",
                url: "view/AlarmCfg/alarmCfgFrame.html",
                apModule: "app/AlarmCfg/alarmCfgFrame"
            },
            "diskCfgFrame": {
                subContainer: "#configRightFrame",
                url: "view/DiskCfg/diskCfgFrame.html",
                apModule: "app/DiskCfg/diskCfgFrame"
            },
            "userCfgFrame": {
                subContainer: "#configRightFrame",
                url: "view/UserMgr/userCfgFrame.html",
                apModule: "app/UserMgr/userCfgFrame"
            },
            "netCfgFrame": {
                subContainer: "#configRightFrame",
                url: "view/NetCfg/netCfgFrame.html",
                apModule: "app/NetCfg/netCfgFrame"
            },
            "systemFrame": {
                subContainer: "#configRightFrame",
                url: "view/System/systemFrame.html",
                apModule: "app/System/systemFrame"
            },

            // 二级模块
            "addChl": {
                url: "view/ChlCfg/addChl.html",
                apModule: "app/ChlCfg/addChl"
            },
            "chlMgr": {
                url: "view/ChlCfg/chlMgr.html",
                apModule: "app/ChlCfg/chlMgr"
            },
            "addChlGroup": {
                url: "view/ChlCfg/addChlGroup.html",
                apModule: "app/ChlCfg/addChlGroup"
            },
            "chlGroupMgr": {
                url: "view/ChlCfg/chlGroupMgr.html",
                apModule: "app/ChlCfg/chlGroupMgr"
            },
            "chlSignal": {
                url: "view/ChlCfg/chlSignal.html",
                apModule: "app/ChlCfg/chlSignal"
            },
            "displaySet": {
                url: "view/ChlCfg/displaySet.html",
                apModule: "app/ChlCfg/displaySet"
            },
            "osd": {
                url: "view/ChlCfg/osd.html",
                apModule: "app/ChlCfg/osd"
            },
            "videoMask": {
                url: "view/ChlCfg/videoMask.html",
                apModule: "app/ChlCfg/videoMask"
            },
            "logoSet": {
                url: "view/ChlCfg/logoSet.html",
                apModule: "app/ChlCfg/logoSet"
            },
            "signalShelter": {
                url: "view/ChlCfg/signalShelter.html",
                apModule: "app/ChlCfg/signalShelter"
            },
            "waterMark": {
                url: "view/ChlCfg/waterMark.html",
                apModule: "app/ChlCfg/waterMark"
            },
            "motion": {
                url: "view/ChlCfg/motion.html",
                apModule: "app/ChlCfg/motion"
            },
            "osc": {
                url: "view/ChlCfg/osc.html",
                apModule: "app/ChlCfg/osc"
            },
            "avd": {
                url: "view/ChlCfg/avd.html",
                apModule: "app/ChlCfg/avd"
            },
            "tripwire": {
                url: "view/ChlCfg/tripwire.html",
                apModule: "app/ChlCfg/tripwire"
            },
            "pea": {
                url: "view/ChlCfg/pea.html",
                apModule: "app/ChlCfg/pea"
            },
            "ptzProtocol": {
                url: "view/ChlCfg/ptzProtocol.html",
                apModule: "app/ChlCfg/ptzProtocol"
            },
            "preset": {
                url: "view/ChlCfg/preset.html",
                apModule: "app/ChlCfg/preset"
            },
            "cruise": {
                url: "view/ChlCfg/cruise.html",
                apModule: "app/ChlCfg/cruise"
            },
            //录像设置
            "recModeCfg": {
                url: "view/RecCfg/recModeCfg.html",
                apModule: "app/RecCfg/recModeCfg"
            },
            "recParamCfg": {
                url: "view/RecCfg/recParamCfg.html",
                apModule: "app/RecCfg/recParamCfg"
            },
            "eventRecStream": {
                url: "view/RecCfg/eventRecStream.html",
                apModule: "app/RecCfg/eventRecStream"
            },
            "timingRecStream": {
                url: "view/RecCfg/timingRecStream.html",
                apModule: "app/RecCfg/timingRecStream"
            },
            "subStream": {
                url: "view/RecCfg/subStream.html",
                apModule: "app/RecCfg/subStream"
            },
            "scheduleRecCfg": {
                url: "view/RecCfg/scheduleRecCfg.html",
                apModule: "app/RecCfg/scheduleRecCfg"
            },
            "addSchedule": {
                url: "view/RecCfg/addSchedule.html",
                apModule: "app/RecCfg/addSchedule"
            },
            "scheduleMgr": {
                url: "view/RecCfg/scheduleMgr.html",
                apModule: "app/RecCfg/scheduleMgr"
            },
            "eventRecCfg": {
                url: "view/RecCfg/eventRecCfg.html",
                apModule: "app/RecCfg/eventRecCfg"
            },
            "viewRecStatus": {
                url: "view/RecCfg/viewRecStatus.html",
                apModule: "app/RecCfg/viewRecStatus"
            },
            //报警模块
            "alarmOut": {
                url: "view/AlarmCfg/alarmOut.html",
                apModule: "app/AlarmCfg/alarmOut"
            },
            "alarmEmail": {
                url: "view/AlarmCfg/alarmEmail.html",
                apModule: "app/AlarmCfg/alarmEmail"
            },
            "alarmDisplay": {
                url: "view/AlarmCfg/alarmDisplay.html",
                apModule: "app/AlarmCfg/alarmDisplay"
            },
            "beeper": {
                url: "view/AlarmCfg/beeper.html",
                apModule: "app/AlarmCfg/beeper"
            },
            "audioAlarmOut": {
                url: "view/AlarmCfg/audioAlarmOut.html",
                apModule: "app/AlarmCfg/audioAlarmOut"
            },
            "alarmAddSchedule": {
                url: "view/RecCfg/addSchedule.html",
                apModule: "app/RecCfg/addSchedule"
            },
            "alarmScheduleMgr": {
                url: "view/RecCfg/scheduleMgr.html",
                apModule: "app/RecCfg/scheduleMgr"
            },
            "pushMessage": {
                url: "view/AlarmCfg/pushMessage.html",
                apModule: "app/AlarmCfg/pushMessage"
            },
            "alarmServer": {
                url: "view/AlarmCfg/alarmServer.html",
                apModule: "app/AlarmCfg/alarmServer"
            },
            "motionAlarmCfg": {
                url: "view/AlarmCfg/motionAlarmCfg.html",
                apModule: "app/AlarmCfg/motionAlarmCfg"
            },
            "oscAlarmCfg": {
                url: "view/AlarmCfg/oscAlarmCfg.html",
                apModule: "app/AlarmCfg/oscAlarmCfg"
            },
            "avdAlarmCfg": {
                url: "view/AlarmCfg/avdAlarmCfg.html",
                apModule: "app/AlarmCfg/avdAlarmCfg"
            },
            "tripwireAlarmCfg": {
                url: "view/AlarmCfg/tripwireAlarmCfg.html",
                apModule: "app/AlarmCfg/tripwireAlarmCfg"
            },
            "peaAlarmCfg": {
                url: "view/AlarmCfg/peaAlarmCfg.html",
                apModule: "app/AlarmCfg/peaAlarmCfg"
            },
            "sensorAlarmCfg": {
                url: "view/AlarmCfg/sensorAlarmCfg.html",
                apModule: "app/AlarmCfg/sensorAlarmCfg"
            },
            "abnormalAlarmCfg": {
                url: "view/AlarmCfg/abnormalAlarmCfg.html",
                apModule: "app/AlarmCfg/abnormalAlarmCfg"
            },
            "devOfflineAlarmCfg": {
                url: "view/AlarmCfg/devOfflineAlarmCfg.html",
                apModule: "app/AlarmCfg/devOfflineAlarmCfg"
            },
            "videoLossAlarmCfg": {
                url: "view/AlarmCfg/videoLossAlarmCfg.html",
                apModule: "app/AlarmCfg/videoLossAlarmCfg"
            },
            "viewAlarmStatus": {
                url: "view/AlarmCfg/viewAlarmStatus.html",
                apModule: "app/AlarmCfg/viewAlarmStatus"
            },
            //磁盘模块
            "diskManagement": {
                url: "view/DiskCfg/diskManagement.html",
                apModule: "app/DiskCfg/diskManagement"
            },
            "storageModeCfg": {
                url: "view/DiskCfg/storageModeCfg.html",
                apModule: "app/DiskCfg/storageModeCfg"
            },
            "viewDiskInfo": {
                url: "view/DiskCfg/viewDiskInfo.html",
                apModule: "app/DiskCfg/viewDiskInfo"
            },
            "viewSmartInfo": {
                url: "view/DiskCfg/viewSmartInfo.html",
                apModule: "app/DiskCfg/viewSmartInfo"
            },
            //账户和安全模块
            "addUser": {
                url: "view/UserMgr/addUser.html",
                apModule: "app/UserMgr/addUser"
            },
            "userMgr": {
                url: "view/UserMgr/userMgr.html",
                apModule: "app/UserMgr/userMgr"
            },
            "addAuthGroup": {
                url: "view/UserMgr/addAuthGroup.html",
                apModule: "app/UserMgr/addAuthGroup"
            },
            "authGroupMgr": {
                url: "view/UserMgr/authGroupMgr.html",
                apModule: "app/UserMgr/authGroupMgr"
            },
            "filterRule": {
                url: "view/UserMgr/filterRule.html",
                apModule: "app/UserMgr/filterRule"
            },
            "logoutViewAuthCfg": {
                url: "view/UserMgr/logoutViewAuthCfg.html",
                apModule: "app/UserMgr/logoutViewAuthCfg"
            },
            "passwordSecurity": {
                url: "view/UserMgr/passwordSecurity.html",
                apModule: "app/UserMgr/passwordSecurity"
            },
            "userStatus": {
                url: "view/UserMgr/userStatus.html",
                apModule: "app/UserMgr/userStatus"
            },
            //网络模块
            "netBase": {
                url: "view/NetCfg/netBase.html",
                apModule: "app/NetCfg/netBase"
            },
            "email": {
                url: "view/NetCfg/email.html",
                apModule: "app/NetCfg/email"
            },
            "pppoe": {
                url: "view/NetCfg/pppoe.html",
                apModule: "app/NetCfg/pppoe"
            },
            "port": {
                url: "view/NetCfg/port.html",
                apModule: "app/NetCfg/port"
            },
            "ddns": {
                url: "view/NetCfg/ddns.html",
                apModule: "app/NetCfg/ddns"
            },
            "802": {
                url: "view/NetCfg/802.html",
                apModule: "app/NetCfg/802"
            },
            "upnp": {
                url: "view/NetCfg/upnp.html",
                apModule: "app/NetCfg/upnp"
            },
            "nat": {
                url: "view/NetCfg/nat.html",
                apModule: "app/NetCfg/nat"
            },
            "https": {
                url: "view/NetCfg/https.html",
                apModule: "app/NetCfg/https"
            },
            "platform": {
                url: "view/NetCfg/platform.html",
                apModule: "app/NetCfg/platform"
            },
            "ftp": {
                url: "view/NetCfg/ftp.html",
                apModule: "app/NetCfg/ftp"
            },
            "snmp": {
                url: "view/NetCfg/snmp.html",
                apModule: "app/NetCfg/snmp"
            },
            "netStatus": {
                url: "view/NetCfg/netStatus.html",
                apModule: "app/NetCfg/netStatus"
            },
            "onlineVideo": {
                url: "view/NetCfg/onlineVideo.html",
                apModule: "app/NetCfg/onlineVideo"
            },
            //系统模块
            "commonCfg":{
                url: "view/System/commonCfg.html",
                apModule: "app/System/commonCfg"
            },
            "dateAndTime":{
                url: "view/System/dateAndTime.html",
                apModule: "app/System/dateAndTime"
            },
            "posCfg":{
                url: "view/System/posCfg.html",
                apModule: "app/System/posCfg"
            },
            "osdCfg":{
                url: "view/System/osdCfg.html",
                apModule: "app/System/osdCfg"
            },
            "viewLog":{
                url: "view/System/viewLog.html",
                apModule: "app/System/viewLog"
            },
            "factoryReset":{
                url: "view/System/factoryReset.html",
                apModule: "app/System/factoryReset"
            },
            "upgrade":{
                url: "view/System/upgrade.html",
                apModule: "app/System/upgrade"
            },
            "backupRestore":{
                url: "view/System/backupRestore.html",
                apModule: "app/System/backupRestore"
            },
            "reboot":{
                url: "view/System/reboot.html",
                apModule: "app/System/reboot"
            },
            "upgradeOnline":{
                url: "view/System/upgradeOnline.html",
                apModule: "app/System/upgradeOnline"
            },
            "timeRestart":{
                url: "view/System/timeRestart.html",
                apModule: "app/System/timeRestart"
            },
            "devBasicInfo":{
                url: "view/System/devBasicInfo.html",
                apModule: "app/System/devBasicInfo"
            },
            "chlStatus":{
                url: "view/System/chlStatus.html",
                apModule: "app/System/chlStatus"
            },
            "platformParam":{
                url: "view/System/platformParam.html",
                apModule: "app/System/platformParam"
            },
            "timedImageUpload":{
                url: "view/System/timedImageUpload.html",
                apModule: "app/System/timedImageUpload"
            },
            "alarmImageUpload":{
                url: "view/System/alarmImageUpload.html",
                apModule: "app/System/alarmImageUpload"
            },
            "platformOperation":{
                url: "view/System/platformOperation.html",
                apModule: "app/System/platformOperation"
            }
        };

        //路由映射表
        var routeMap = {
            "login": {
                path: "login",
                lk: ""
            },
            "live": {
                path: "main/live",
                lk: ""
            },
            "record": {
                path: "main/rec",
                lk: ""
            },
            "record/backup": {
                path: "main/recBackUp",
                lk: ""
            },
            "config/local": {
                path: "main/localConfig",
                lk: ""
            },
            "config/home": {
                path: "main/cfgHome",
                lk: "IDCS_FUNCTION_PANEL"
            },
            "config/channel/list": {
                path: "main/chlCfgFrame/chlMgr",
                lk: "IDCS_CHANGE_OR_DELETE_CHANNEL",
                navSequence: ['config/home', 'config/channel/list']
            },
            "config/channel/add": {
                path: "main/chlCfgFrame/addChl",
                lk: "IDCS_ADD_CHANNEL",
                navSequence: ['config/home', 'config/channel/list', 'config/channel/add']
            },
            "config/channel/group/list": {
                path: "main/chlCfgFrame/chlGroupMgr",
                lk: "IDCS_CHANGE_OR_DELETE_CHANNEL_GROUP",
                navSequence: ['config/home', 'config/channel/group/list']
            },
            "config/channel/group/add": {
                path: "main/chlCfgFrame/addChlGroup",
                lk: "IDCS_ADD_GROUP",
                navSequence: ['config/home', 'config/channel/group/list', 'config/channel/group/add']
            },
            "config/channel/signal": {
                path: "main/chlCfgFrame/chlSignal",
                lk: "IDCS_CHANNEL_SIGNAL_ACCESS_SET",
                navSequence: ['config/home', 'config/channel/signal']
            },
            "config/channel/settings/image": {
                path: "main/chlCfgFrame/displaySet",
                lk: "IDCS_IMAGE_PARAMETER_SETTING",
                navSequence: ['config/home', 'config/channel/settings/image']
            },
            "config/channel/settings/osd": {
                path: "main/chlCfgFrame/osd",
                lk: "IDCS_OSD_SETTING",
                navSequence: ['config/home', 'config/channel/settings/osd']
            },
            "config/channel/settings/mask": {
                path: "main/chlCfgFrame/videoMask",
                lk: "IDCS_VIDEO_MASK_SETTING",
                navSequence: ['config/home', 'config/channel/settings/mask']
            },
            "config/channel/settings/logoSet": {
                path: "main/chlCfgFrame/logoSet",
                lk: "IDCS_LOGO_SETTINGS",
                navSequence: ['config/home', 'config/channel/settings/logoSet']
            },
            "config/channel/settings/signalshelter": {
                path: "main/chlCfgFrame/signalShelter",
                lk: "IDCS_SIGNAL_SHELTER_SETTING",
                navSequence: ['config/home', 'config/channel/settings/signalshelter']
            },
            "config/channel/settings/watermark": {
                path: "main/chlCfgFrame/waterMark",
                lk: "IDCS_WATER_MARK_SETTING",
                navSequence: ['config/home', 'config/channel/settings/watermark']
            },
            "config/channel/settings/motion": {
                path: "main/chlCfgFrame/motion",
                lk: "IDCS_MOTION_SETTING",
                navSequence: ['config/home', 'config/channel/settings/motion']
            },
            "config/channel/intelligence/osc": {
                path: "main/chlCfgFrame/osc",
                lk: "IDCS_WATCH_DETECTION",
                navSequence: ['config/home', 'config/channel/intelligence/osc']
            },
            "config/channel/intelligence/avd": {
                path: "main/chlCfgFrame/avd",
                lk: "IDCS_ABNORMAL_DETECTION",
                navSequence: ['config/home', 'config/channel/intelligence/avd']
            },
            "config/channel/intelligence/tripwire": {
                path: "main/chlCfgFrame/tripwire",
                lk: "IDCS_BEYOND_DETECTION",
                navSequence: ['config/home', 'config/channel/intelligence/tripwire']
            },
            "config/channel/intelligence/pea": {
                path: "main/chlCfgFrame/pea",
                lk: "IDCS_INVADE_DETECTION",
                navSequence: ['config/home', 'config/channel/intelligence/pea']
            },
            "config/channel/ptz/protocol": {
                path: "main/chlCfgFrame/ptzProtocol",
                lk: "IDCS_PROTOCOL",
                navSequence: ['config/home', 'config/channel/ptz/protocol']
            },
            "config/channel/ptz/preset": {
                path: "main/chlCfgFrame/preset",
                lk: "IDCS_PRESET",
                navSequence: ['config/home', 'config/channel/ptz/preset']
            },
            "config/channel/ptz/cruise": {
                path: "main/chlCfgFrame/cruise",
                lk: "IDCS_CRUISE",
                navSequence: ['config/home', 'config/channel/ptz/cruise']
            },
            //录像管理
            "config/record/mode": {
                path: "main/recCfgFrame/recModeCfg",
                lk: "IDCS_MODE_SET",
                navSequence: ['config/home', 'config/record/mode']
            },
            "config/record/parameter": {
                path: "main/recCfgFrame/recParamCfg",
                lk: "IDCS_PARAM_SET",
                navSequence: ['config/home', 'config/record/parameter']
            },
            "config/record/stream/event": {
                path: "main/recCfgFrame/eventRecStream",
                lk: "IDCS_EVENT_RECORD_CODE_STREAM",
                navSequence: ['config/home', 'config/record/stream/event']
            },
            "config/record/stream/timing": {
                path: "main/recCfgFrame/timingRecStream",
                lk: "IDCS_TIME_RECORD_CODE_STREAM",
                navSequence: ['config/home', 'config/record/stream/timing']
            },
            "config/record/schedule": {
                path: "main/recCfgFrame/scheduleRecCfg",
                lk: "IDCS_SCHEDULE_OF_RECORD_SET",
                navSequence: ['config/home', 'config/record/schedule']
            },
            "config/record/schedule/add": {
                path: "main/recCfgFrame/addSchedule",
                lk: "IDCS_ADD_SCHEDULE",
                navSequence: ['config/home', 'config/alarm/schedule/manager', 'config/record/schedule/add']
            },
            "config/record/schedule/manager": {
                path: "main/recCfgFrame/scheduleMgr",
                lk: "IDCS_SCHEDULE_MANAGE",
                navSequence: ['config/home', 'config/record/schedule/manager']
            },
            "config/record/event": {
                path: "main/recCfgFrame/eventRecCfg",
                lk: "IDCS_EVENT_RECORD_SET",
                navSequence: ['config/home', 'config/record/event']
            },
            "config/record/status": {
                path: "main/recCfgFrame/viewRecStatus",
                lk: "IDCS_VIEW_RECORD_STATE",
                navSequence: ['config/home', 'config/record/status']
            },
            //报警模块
            "config/alarm/alarm_out": {
                path: "main/alarmCfgFrame/alarmOut",
                lk: "IDCS_ALARM_OUT",
                navSequence: ['config/home', 'config/alarm/alarm_out']
            },
            "config/alarm/email/recipients": {
                path: "main/alarmCfgFrame/alarmEmail",
                lk: "IDCS_EMAIL",
                navSequence: ['config/home', 'config/alarm/email/recipients']
            },
            "config/alarm/display": {
                path: "main/alarmCfgFrame/alarmDisplay",
                lk: "IDCS_DISPLAY",
                navSequence: ['config/home', 'config/alarm/display']
            },
            "config/alarm/audioAlarmOut": {
                path: "main/alarmCfgFrame/audioAlarmOut",
                lk: "IDCS_AUDIO",
                navSequence: ['config/home', 'config/alarm/audioAlarmOut']
            },
            "config/alarm/beeper": {
                path: "main/alarmCfgFrame/beeper",
                lk: "IDCS_BUZZER",
                navSequence: ['config/home', 'config/alarm/beeper']
            },
            "config/alarm/schedule/add": {
                path: "main/alarmCfgFrame/alarmAddSchedule",
                lk: "IDCS_ADD_SCHEDULE",
                navSequence: ['config/home', 'config/alarm/schedule/manager', 'config/alarm/schedule/add']
            },
            "config/alarm/schedule/manager": {
                path: "main/alarmCfgFrame/alarmScheduleMgr",
                lk: "IDCS_SCHEDULE_MANAGE",
                navSequence: ['config/home', 'config/alarm/schedule/manager']
            },
            "config/alarm/message/push": {
                path: "main/alarmCfgFrame/pushMessage",
                lk: "IDCS_PUSH_MESSAGE",
                navSequence: ['config/home', 'config/alarm/message/push']
            },
            "config/alarm/server": {
                path: "main/alarmCfgFrame/alarmServer",
                lk: "IDCS_ALARM_SERVER",
                navSequence: ['config/home', 'config/alarm/server']
            },
            "config/alarm/motion": {
                path: "main/alarmCfgFrame/motionAlarmCfg",
                lk: "IDCS_MOTION_DETECT_ALARM",
                navSequence: ['config/home', 'config/alarm/motion']
            },
            "config/alarm/osc": {
                path: "main/alarmCfgFrame/oscAlarmCfg",
                lk: "IDCS_WATCH_DETECTION",
                navSequence: ['config/home', 'config/alarm/osc']
            },
            "config/alarm/avd": {
                path: "main/alarmCfgFrame/avdAlarmCfg",
                lk: "IDCS_ABNORMAL_DISPOSE_WAY",
                navSequence: ['config/home', 'config/alarm/avd']
            },
            "config/alarm/tripwire": {
                path: "main/alarmCfgFrame/tripwireAlarmCfg",
                lk: "IDCS_BEYOND_DETECTION",
                navSequence: ['config/home', 'config/alarm/tripwire']
            },
            "config/alarm/pea": {
                path: "main/alarmCfgFrame/peaAlarmCfg",
                lk: "IDCS_INVADE_DETECTION",
                navSequence: ['config/home', 'config/alarm/pea']
            },
            "config/alarm/sensor": {
                path: "main/alarmCfgFrame/sensorAlarmCfg",
                lk: "IDCS_DISPOSE_WAY_SET",
                navSequence: ['config/home', 'config/alarm/sensor']
            },
            "config/alarm/abnormal": {
                path: "main/alarmCfgFrame/abnormalAlarmCfg",
                lk: "IDCS_SYSTEM_ABNORMAL_DISPOSE_WAY_SET",
                navSequence: ['config/home', 'config/alarm/abnormal']
            },
            "config/alarm/device/offline": {
                path: "main/alarmCfgFrame/devOfflineAlarmCfg",
                lk: "IDCS_IPC_OFFLINE_SET",
                navSequence: ['config/home', 'config/alarm/device/offline']
            },
            "config/alarm/video/loss": {
                path: "main/alarmCfgFrame/videoLossAlarmCfg",
                lk: "IDCS_VIDEO_LOSE_SET",
                navSequence: ['config/home', 'config/alarm/video/loss']
            },
            "config/alarm/status": {
                path: "main/alarmCfgFrame/viewAlarmStatus",
                lk: "IDCS_VIEW_ALARM_STATE",
                navSequence: ['config/home', 'config/alarm/status']
            },
            //磁盘模块
            "config/disk/manager": {
                path: "main/diskCfgFrame/diskManagement",
                lk: "IDCS_DISK_MANAGE",
                navSequence: ['config/home', 'config/disk/manager']
            },
            "config/disk/storage/mode": {
                path: "main/diskCfgFrame/storageModeCfg",
                lk: "IDCS_STORAGE_MODE_SET",
                navSequence: ['config/home', 'config/disk/storage/mode']
            },
            "config/disk/information": {
                path: "main/diskCfgFrame/viewDiskInfo",
                lk: "IDCS_VIEW_DISK_INFORMATION",
                navSequence: ['config/home', 'config/disk/information']
            },
            "config/disk/information/smart": {
                path: "main/diskCfgFrame/viewSmartInfo",
                lk: "IDCS_DISK_SMART_INFO",
                navSequence: ['config/home', 'config/disk/information/smart']
            },
            //账户和安全模块
            "config/security/user/add": {
                path: "main/userCfgFrame/addUser",
                lk: "IDCS_ADD_USER",
                navSequence: ['config/home', 'config/security/user/list', 'config/security/user/add']
            },
            "config/security/user/list": {
                path: "main/userCfgFrame/userMgr",
                lk: "IDCS_CHANGE_OR_DELETE_USER",
                navSequence: ['config/home', 'config/security/user/list']
            },
            "config/security/auth_group/add": {
                path: "main/userCfgFrame/addAuthGroup",
                lk: "IDCS_ADD_USER_RIGHT",
                navSequence: ['config/home', 'config/security/auth_group/list', 'config/security/auth_group/add']
            },
            "config/security/auth_group/list": {
                path: "main/userCfgFrame/authGroupMgr",
                lk: "IDCS_CHANGE_OR_DELETE_RIGHT_GROUP",
                navSequence: ['config/home', 'config/security/auth_group/list']
            },
            "config/security/rule/filter": {
                path: "main/userCfgFrame/filterRule",
                lk: "IDCS_BLACK_AND_WHITE_LIST",
                navSequence: ['config/home', 'config/security/rule/filter']
            },
            "config/security/preview/logout": {
                path: "main/userCfgFrame/logoutViewAuthCfg",
                lk: "IDCS_PREVIEW_AUTHORITY_AFTER_LOGOUT",
                navSequence: ['config/home', 'config/security/preview/logout']
            },
            "config/security/passwordSecurity": {
                path: "main/userCfgFrame/passwordSecurity",
                lk: "IDCS_PASSWORD_SAFETY",
                navSequence: ['config/home', 'config/security/passwordSecurity']
            },
            "config/security/user/status": {
                path: "main/userCfgFrame/userStatus",
                lk: "IDCS_ONLINE_USER",
                navSequence: ['config/home', 'config/security/user/status']
            },
            //网络模块
            "config/net/stream/sub": {
                path: "main/netCfgFrame/subStream",
                lk: "IDCS_SUB_STREAM_SET",
                navSequence: ['config/home', 'config/net/stream/sub']
            },
            "config/net/tcp_ip": {
                path: "main/netCfgFrame/netBase",
                lk: "IDCS_TCP_IPV4",
                navSequence: ['config/home', 'config/net/tcp_ip']
            },
            "config/net/email": {
                path: "main/netCfgFrame/email",
                lk: "IDCS_EMAIL",
                navSequence: ['config/home', 'config/net/email']
            },
            "config/net/pppoe": {
                path: "main/netCfgFrame/pppoe",
                lk: "PPPOE",
                navSequence: ['config/home', 'config/net/pppoe']
            },
            "config/net/ddns": {
                path: "main/netCfgFrame/ddns",
                lk: "DDNS",
                navSequence: ['config/home', 'config/net/ddns']
            },
            "config/net/802": {
                path: "main/netCfgFrame/802",
                lk: "802.1x",
                navSequence: ['config/home', 'config/net/802']
            },
            "config/net/port": {
                path: "main/netCfgFrame/port",
                lk: "IDCS_PORT",
                navSequence: ['config/home', 'config/net/port']
            },
            "config/net/upnp": {
                path: "main/netCfgFrame/upnp",
                lk: "IDCS_UPNP",
                navSequence: ['config/home', 'config/net/upnp']
            },
            "config/net/nat": {
                path: "main/netCfgFrame/nat",
                lk: "IDCS_NAT",
                navSequence: ['config/home', 'config/net/nat']
            },
            "config/net/https": {
                path: "main/netCfgFrame/https",
                lk: "IDCS_HTTPS",
                navSequence: ['config/home', 'config/net/https']
            },
            "config/net/platform": {
                path: "main/netCfgFrame/platform",
                lk: "IDCS_PLATFORM_ACCESS",
                navSequence: ['config/home', 'config/net/platform']
            },
            "config/net/ftp": {
                path: "main/netCfgFrame/ftp",
                lk: "FTP",
                navSequence: ['config/home', 'config/net/ftp']
            },
            "config/net/snmp": {
                path: "main/netCfgFrame/snmp",
                lk: "IDCS_SNMP",
                navSequence: ['config/home', 'config/net/snmp']
            },
            "config/net/status": {
                path: "main/netCfgFrame/netStatus",
                lk: "IDCS_VIEW_NETWORK_STATE",
                navSequence: ['config/home', 'config/net/status']
            },
            "config/net/video/online": {
                path: "main/netCfgFrame/onlineVideo",
                lk: "IDCS_ONLINE_VIDEO_LINK",
                navSequence: ['config/home', 'config/net/video/online']
            },
            //系统模块
            "config/system/common": {
                path: "main/systemFrame/commonCfg",
                lk: "IDCS_GENERAL_SET",
                navSequence: ['config/home', 'config/system/common']
            },
            "config/system/time": {
                path: "main/systemFrame/dateAndTime",
                lk: "IDCS_DATE_AND_TIME",
                navSequence: ['config/home', 'config/system/time']
            },
            "config/system/pos": {
                path: "main/systemFrame/posCfg",
                lk: "IDCS_POS_CONFIG",
                navSequence: ['config/home', 'config/system/pos']
            },
            "config/system/osd": {
                path: "main/systemFrame/osdCfg",
                lk: "IDCS_OSD_CONFIG",
                navSequence: ['config/home', 'config/system/osd']
            },
            "config/system/log": {
                path: "main/systemFrame/viewLog",
                lk: "IDCS_VIEW_LOG",
                navSequence: ['config/home', 'config/system/log']
            },
            "config/system/restore_factory_settings": {
                path: "main/systemFrame/factoryReset",
                lk: "IDCS_DEFAULT_SET",
                navSequence: ['config/home', 'config/system/restore_factory_settings']
            },
            "config/system/upgrade": {
                path: "main/systemFrame/upgrade",
                lk: "IDCS_UPGRADE",
                navSequence: ['config/home', 'config/system/upgrade']
            },
            "config/system/upgradeOnline": {
                path: "main/systemFrame/upgradeOnline",
                lk: "IDCS_ONLINE_UPGRADE",
                navSequence: ['config/home', 'config/system/upgradeOnline']
            },
            "config/system/backup_and_restore": {
                path: "main/systemFrame/backupRestore",
                lk: "IDCS_BACKUP_AND_RESTORE_SET",
                navSequence: ['config/home', 'config/system/backup_and_restore']
            },
            "config/system/reboot": {
                path: "main/systemFrame/reboot",
                lk: "IDCS_SYSTEM_REBOOT",
                navSequence: ['config/home', 'config/system/reboot']
            },
            "config/system/maintenance/auto": {
                path: "main/systemFrame/timeRestart",
                lk: "IDCS_AUTO_MAINTENANCE",
                navSequence: ['config/home', 'config/system/maintenance/auto']
            },
            "config/system/information": {
                path: "main/systemFrame/devBasicInfo",
                lk: "IDCS_DEVICE_BASIC_INFORMATION",
                navSequence: ['config/home', 'config/system/information']
            },
            "config/system/channel/status": {
                path: "main/systemFrame/chlStatus",
                lk: "IDCS_CHANNEL_STATE",
                navSequence: ['config/home', 'config/system/channel/status']
            },
            "config/system/platform/parameter": {
                path: "main/systemFrame/platformParam",
                lk: "IDCS_PLATFORM_PARAMETER",
                navSequence: ['config/home', 'config/system/platform/parameter']
            },
            "config/system/upload/image/timing": {
                path: "main/systemFrame/timedImageUpload",
                lk: "IDCS_SCHEDULE_PIC_UPLOAD",
                navSequence: ['config/home', 'config/system/upload/image/timing']
            },
            "config/system/upload/image/alarm": {
                path: "main/systemFrame/alarmImageUpload",
                lk: "IDCS_ALARM_PIC_UPLOAD",
                navSequence: ['config/home', 'config/system/upload/image/alarm']
            },
            "config/system/platform/operation": {
                path: "main/systemFrame/platformOperation",
                lk: "IDCS_PLATFORM_OPERATE_MANAGE",
                navSequence: ['config/home', 'config/system/platform/operation']
            }
        };

        function init(url) {
            defaultUrl = url;
            $(window).bind('hashchange', _doNav);
        }

        function autoHeight() {
            $("#Content").height(document.body.clientHeight - 118);
        }

        $(window).resize(function () {
            autoHeight();
        });


        //解析路径
        function parsePath(url) {
            if (!url) return null;
            var path = routeMap[url].path;
            path = path.split("/");
            return $.grep(path, function (n, i) {
                return n.length > 0;
            }, false);
        }


        function _doNav() {
            //解析导航路径
            var newRouteUrl, uHash = location.hash;
            if (uHash.length > 0) {
                newRouteUrl = uHash.substr(1);
            }
            else
                newRouteUrl = null;

            //非法路径，恢复到上一次的有效路径或默认路径
            if (!(newRouteUrl in routeMap)) {
                if (routeUrl)
                    doNav(routeUrl);
                else
                    doNav(defaultUrl);
                return;
            }
            //如果地址没有发生变化，什么也不做
            if (newRouteUrl == routeUrl)
                return;

            routeUrl = newRouteUrl;

            var lastRoutePath = parsePath(lastRouteUrl);
            var routePath = parsePath(routeUrl);

            var navPathIndex = 0;
            //对比新旧导航路径，计算出界面刷新的Index
            if (lastRoutePath != null && lastRoutePath.length > 0) {
                for (var i = 0; i < routePath.length; i++) {
                    if (lastRoutePath[i] == null || routePath[i] != lastRoutePath[i]) {
                        navPathIndex = i;
                        break;
                    }
                }
            }

            //如果新的导航路径为空，导航到默认页
            if (routePath == null || routePath.length == 0) {
                doNav(defaultUrl);
                return;
            }//如果导航地址没有变化，则不导航
            else if (navPathIndex >= routePath.length) {
                routeUrl = lastRouteUrl;
                return;
            }


            //$("body").css({visibility: 'hidden', opacity: 0});
            $("body").css({opacity: 0});
            //依次从下到上调用当前导航页面Index以下（包含当前导航页面Index）的旧页面树的beforeUnload
            if (lastRoutePath != null) {
                var neesUnloadApModuleNames = [];
                var parentContents = [];
                for (var i = lastRoutePath.length - 1; i >= navPathIndex; i--) {
                    var apId = lastRoutePath[i];
                    if (apId in appModuleList) {
                        neesUnloadApModuleNames.push(appModuleList[apId]["apModule"]);
                        if (lastRoutePath[i - 1] && lastRoutePath[i - 1] in appModuleList && appModuleList[lastRoutePath[i - 1]]["subContainer"])
                            parentContents.push($(appModuleList[lastRoutePath[i - 1]]["subContainer"]));
                        else
                            parentContents.push(null);
                    }
                }
                //这里是异步的，有可能会产生先加载了新AP模块，后释放旧AP模块的情况，所以当有旧AP模块需要释放时，加载新AP模块要放在请求旧AP模块的工厂方法里面
                require(neesUnloadApModuleNames,
                    function () {
                        for (var i=0; i<arguments.length; i++) {
                            if (arguments[i]) {
                                if (("BeforeUnload" in arguments[i]))
                                    arguments[i]["BeforeUnload"]();

                                //在去掉CSS前，要将View区域置空，否则会存在没有样式但元素依然存在的时间，虽然已将body的透明度置为0，但这时依然可能会产生显示异常，如没有样式的元素变大可能导致出现body出现滚动条
                                if (parentContents[i])
                                    parentContents[i].empty();

                                if (("UnloadCss" in arguments[i])) {
                                    arguments[i]["UnloadCss"]();
                                }
                            }
                        }
                        routeToNewUrl(navPathIndex, routePath);
                    });
            }
            else {
                routeToNewUrl(navPathIndex, routePath);
            }
        }

        function routeToNewUrl(navPathIndex, routePath) {
            route(navPathIndex, routePath);
            setCfgNavBar(routeUrl);
            lastRouteUrl = routeUrl;
            //触发路由地址改变事件
            routeUrlChangedEvent.emit(routeUrl);
        }

        function setCfgNavBar(routeUrl, $navBar) {
            var routeUrlItem = routeMap[routeUrl];
            if ("navSequence" in routeUrlItem) {
                var navSequence = routeUrlItem["navSequence"];
                var navBarHtml = "";
                for (var i = 0; i < navSequence.length; i++) {
                    if (i > 0)
                        navBarHtml += "<div alt=\"nav\"></div>";
                    navBarHtml += "<a href=\"javascript:Route.DoNav('" + navSequence[i] + "')\" >" + LangCtrl._L_(routeMap[navSequence[i]]["lk"]) + "</a>";
                }

                $("#navBar").html(navBarHtml);
            }
        }

        function bindRouteEvent($container, evt) {
            evt = evt || "click";
            $("[routeUrl]", $container).unbind(evt).bind(evt, function (e) {
                if (e.stopPropagation)
                    e.stopPropagation();
                doNav($(this).attr("routeUrl"));
            });
        }

        //导航
        function doNav(routeUrl) {
            var oldRouteUrl = getCurrentRouteUrl();
            if (oldRouteUrl == routeUrl) {
                _doNav();
            }
            else {
                location.hash = "#" + routeUrl;
            }
        }

        function navToInitUrl() {
            var url = $.webSession("path");
            if (!url) url = getCurrentRouteUrl();
            if (url === "login") url = defaultUrl;
            doNav(url);
        }

        function getCurrentRouteUrl() {
            return location.hash.substr(1);
        }


        ///**
        // * 路由
        // * @param {Number} routePathIndex : 目标路径中路由的起始的索引
        // */
        function route(routePathIndex, routePath) {
            try {
                var pageContainer = $("#BaseContent");
                if (routePathIndex > 0) {
                    var preIndexApId = routePath[routePathIndex - 1];
                    if (preIndexApId in appModuleList)
                        pageContainer = $(appModuleList[preIndexApId]["subContainer"]);
                    else
                        throw "Invalid AP ID";
                }
                var apId = routePath[routePathIndex];
                if (apId in appModuleList) {
                    loadApModule(apId, pageContainer, function (apModule) {
                        autoHeight();
                        if (apModule && ("OnLoad" in apModule)) {
                            apModule["OnLoad"]();
                        }
                        routePathIndex++;
                        if (routePathIndex < routePath.length)
                            route(routePathIndex, routePath);
                        else {
                            //$("body").css({visibility: 'visible'});
                            $("body").animate({opacity: 1}, 600, "swing");
                        }
                    });
                }
                else
                    throw "Invalid AP ID";
            }
            catch (ex) {
                doNav(defaultUrl);
            }
        }

        ///**
        // * 加载AP模块
        // * @param {String} url : AP模块ID
        // * @param {JQ Object} pageContainer : 容器元素的JQuery对象
        // * @param {Function} loadCallBack : 加载完AP模块对应的视图后的回调函数
        // */
        function loadApModule(apId, pageContainer, loadCallBack) {
            var apModuleObj = appModuleList[apId];
            require([apModuleObj.apModule],
                function (apModule) {
                    if (!apModule) {
                        //在路由到新的URL之前，已将view清空，这里已不需要调用
                        //pageContainer.empty();
                        //$("body").css({visibility: 'visible'});
                        $("body").animate({opacity: 1}, 600, "swing");
                        return;
                    }
                    if ("LoadCss" in apModule) {
                        apModule["LoadCss"](function () {
                            loadView(apModuleObj, pageContainer, apModule, loadCallBack);
                        });
                    }
                    else
                        loadView(apModuleObj, pageContainer, apModule, loadCallBack);
                });
        }


        ///**
        // * 加载视图
        // * @param {String} url : 目标路径
        // * @param {JQ Object} pageContainer : 容器元素的JQuery对象
        // * @param {Function} loadCallBack : 加载完视图后的回调函数
        // */
        function loadView(apModuleObj, pageContainer, apModule, loadCallBack) {
            var url;
            //菜单对象中有url，则统一加载视图
            if ("url" in apModuleObj) {
                url = apModuleObj.url;
            }
            //如果AP模块对象中有getViewUrl方法，则自己获取要加载视图的url
            else if ("GetViewUrl" in apModule) {
                url = apModule.GetViewUrl();
            }
            else
                throw "Invalid Module";

            Loading.Show();
            //在路由到新的URL之前，已将view清空，这里已不需要调用
            //pageContainer.empty();
            commonOnUnload();

            $.ajax({
                type: "GET",
                cache: false,
                dataType: "html",
                url: url
            }).done(function (data, textStatus, jqXHR) {
                pageContainer.html(data);
                LangCtrl.Translate(pageContainer);
                bindRouteEvent(pageContainer);
                Loading.Hide();
                if (typeof loadCallBack == "function") {
                    loadCallBack(apModule);
                }
            }).fail(function (jqXHR, textStatus, errorThrown) {
                Loading.Hide();
                $(document.body).html("");
            });
        }

        function cleareDislog(context) {
            if (!context) {
                context = document;
            }
            $("div.tvt_dialog_background.closeOnViewSwitch", context).remove();
            $("div.tvt_dialog.closeOnViewSwitch", context).remove();
        }

        function commonOnUnload() {
            cleareDislog(document);
            $("#toolBar").empty();
            $("#Content,#divCopyRight").css("min-width", "1100px");
        }

        function logout(errorCode) {
            var sessionId = "{"+ $.webSession('sessionId') +"}";
            var sendXml = Communication.GetRequestHeader("doLogout") +
                "<content><sessionId><![CDATA[" + sessionId + "]]></sessionId></content>" +
                Communication.GetRequestEnd();

            Communication.Request({
                url: "doLogout",
                data: sendXml,
                checkCommonErrorSwitch: false
            });

            $.webSession('auInfo_N9K', null);
            $.webSession('authGroupId', null);
            $.webSession('analogChlCount', null);
            $.webSession('ipChlMaxCount', null);
            $.webSession('authMask', null);
            $.webSession('authEffective', null);
            $.webSession("userId", null);
            $.webSession("ec", null);
            $.webSession('sessionId', null);
            $.webSession('LiveCache_SegNum', null);
            setTimeout(function () {
                Plugin.DisposePlugin();
            },2000);
            //
            $.webSession('defaultPwd', null);
            $.webSession('isChangedPwd', null);
            $.webSession('pwdSaftyStrength', null);
            $.webSession('pwdExpired', null);
            isFirstLoadStream = true;
            if (APP_TYPE == "STANDARD"){
                setTimeout(function () {
                    Plugin.DisposePlugin();
                },2000);             
                    doNav("login");
            }

            else {
                if (errorCode != undefined)
                    $.cookie("ec", errorCode);
                window.location.href = "/index.html";
            }
        }

        window.Route = {
            /**
             * 初始化
             * @param {String} defaultPath : 默认路径
             */
            Init: init,
            /**
             * 导航
             * @param {String} routePath : 目标路径
             */
            DoNav: doNav,
            /**
             * 导航到初始Url：
             * 初始Url规则：1.已登录时：最后一次访问的有效路径或defaultPath；2.登录后：登录前访问的有效路径或defaultPath
             */
            NavToInitUrl: navToInitUrl,
            /**
             * 路由映射表（地址:路径）
             * 地址，是指浏览器地址栏中可以看到的有url hash表示的字符串，是AP功能的逻辑标识，需语义清晰，表达出功能点之间的逻辑关系， 如：channel/add，channel/list等，隐藏功能点之物理关系
             * 地址对应的路径由 “apId”和 “/” 组成，如：cfgFrame/addChl
             * 由于同一功能可能在不能功能分类下出现，即存在多个入口，所有地址是灵活的，不同地址可以对应同一条路径
             */
            RouteMap: routeMap,
            /**
             * 退出登录
             */
            Logout: logout,
            /**
             * 导航
             * @return {String} : 获取当前浏览器地址栏中的导航地址
             */
            GetCurrentRouteUrl: getCurrentRouteUrl,
            /**
             * 路由地址改变事件
             */
            RouteUrlChangedEvent: routeUrlChangedEvent,

            SetCfgNavBar: setCfgNavBar
        };

        return window.Route;
    });